package com.cjm.one.controller.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.goods.entity.GoodsSku;
import com.cjm.one.model.goods.vo.GoodsSkuVo;
import com.cjm.one.service.GoodsCollectService;
import com.cjm.one.service.GoodsSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "商品分类", description = "商品分类管理")
@RequestMapping("/api/goods/collect")
public class GoodsCollectController {

    @Resource
    private GoodsCollectService goodsCollectService;
    @Resource
    private GoodsSkuService goodsSkuService;

    @GetMapping("/add")
    @Operation(summary = "添加商品收藏")
    public Result<Boolean> insertCollect(@RequestParam("goodsId") Long goodsId){
        return goodsCollectService.insertCollect(goodsId);
    }
    @DeleteMapping("/delete")
    @Operation(summary = "删除商品收藏")
    Result<Boolean> deleteCollect(@RequestParam("id") Long id){
        return goodsCollectService.deleteCollect(id);
    }
    @DeleteMapping("/delete/batch")
    @Operation(summary = "批量删除商品收藏")
    Result<Boolean> deleteCollectBatch(@RequestParam("ids") Long[] ids){
        return goodsCollectService.deleteCollectBatch(ids);
    }
    @GetMapping("/check/sku/{id}")
    @Operation(summary = "检查商品是否收藏")
    public Result<Boolean> checkGoodsCollect(@PathVariable("id") Long id){
        return goodsCollectService.checkGoodsCollect(id);
    }
    @GetMapping("/list")
    @Operation(summary = "查询当前用户收藏的商品列表")
    Result<Page<GoodsSkuVo>> getByCollection(@RequestParam(name = "current",defaultValue = "1") Long current, @RequestParam(name = "size",defaultValue = "10") Long size){
        return goodsSkuService.pageListByCollection(current,size);
    }
}
